﻿using CommunityToolkit.Mvvm.Input;
using Jamesnet.Wpf.Mvvm;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace WpfDemo.ViewModels
{
    public class MainWindowViewModel : ObservableBase
    {
        private readonly string _viewPath = "WpfDemo.Views.";
        private object? _currentMainView;


        public MainWindowViewModel()
        {
            NaviNames = new List<string> { "ButtonView", "CalendarView", "SliderView", "button4", "button5", "IconView" };
        }

        #region 属性
        public object? CurrentMainView
        {
            get { return _currentMainView; }
            set
            {
                SetProperty(ref _currentMainView, value);
            }
        }
        public List<string> NaviNames { get; set; } 
        #endregion


        #region 命令
        private ICommand? _navCommand;
        public ICommand NavCommand => _navCommand ??= new RelayCommand<string>(viewName =>
        {
            var type = Type.GetType(_viewPath + viewName);
            if (type != null)
            {
                var view = App.Current.Services.GetService(type);
                CurrentMainView = view;
            }
        });
        #endregion


    }
}
